package com.hnguigu.ajax.controller;

import com.hnguigu.ajax.dto.UserDTO;
import com.hnguigu.ajax.vo.Result;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/axios")
public class AxiosController {

    @RequestMapping("/test2")
    public String test2() {
        return "test2";
    }

    @RequestMapping("/test4")
    public String test4() {
        return "test4";
    }


    @RequestMapping(value = "/check", method = RequestMethod.POST)
    @ResponseBody
    public Result check(@RequestBody UserDTO userDTO) {
        if ("zhangsan".equals(userDTO.getName())) {
            return new Result("false", "5001", "<font color='red'>此用户已占用！</font>", null);
        } else {
            return new Result("true", "2000", "此用户可以使用：" + userDTO.getName(), null);
        }
    }

}
